package neicun;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class ByeStream {
    public static void main(String[] args) throws IOException {
        //使用内存流
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bao.write("hello world".getBytes());

        //读取
        ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());

        String line = "";
        int bit;
        while ((bit = bis.read()) != -1){
            line += (char)bit;
        }
        System.out.println(line);


        bao.close();
    }
    public static void main1(String[] args) throws IOException {
        //使用内存流
        ByteArrayInputStream bais = new ByteArrayInputStream("hello world".getBytes());
        while (bais.available() > 0) {
            System.out.print((char) bais.read());
        }
        bais.close();
    }
}
